package com.company.责任链模式;

public class Test2 {
    public static void test(Handler2 handler2,Request2 request2){
        handler2.handle2(request2);
    }

    public static void main(String[] args) {
        Handler2 h = new TeamLeader2(new DepLeader2(null));
        test(h,new Request2(4));
    }

}
abstract class Handler2{
    protected Handler2 next;
    public Handler2(Handler2 next){
        this.next=next;
    }
    public abstract void handle2(Request2 request2);
}
class Request2{
    private int days;
    public Request2(int days){
        this.days=days;
    }

    public void setDays(int days) {
        this.days = days;
    }

    public int getDays() {
        return days;
    }
}
class TeamLeader2 extends Handler2{

    public TeamLeader2(Handler2 handler2){
        super(handler2);
    }
    @Override
    public void handle2(Request2 request2) {
        System.out.println("组长通过");
        if (request2.getDays()>3){
            next.handle2(request2);
        }
    }
}
class DepLeader2 extends Handler2{

    public DepLeader2(Handler2 handler2){
        super(handler2);
    }
    @Override
    public void handle2(Request2 request2) {
        System.out.println("主管通过");
        if (request2.getDays()>5){
            next.handle2(request2);
        }
    }
}
